import { createStore } from "redux"


// 定义需求
const INCREMENT = "INCREMENT"
const DECREMENT = "DECREMENT"


const increment = {
    type: INCREMENT
}

const decrement = {
    type: DECREMENT
}

const initalState = {
    value: 0
}

// 定义流水线

function countReducer(state=initalState, action){
    switch(action.type) {
        case INCREMENT:
            return {
                ...state,
                value: state.value + 1
            }
        case DECREMENT:
            return {
                ...state,
                value: state.value - 1
            }
        default:
            return state
    }
}

// 创建仓库
const store = createStore(countReducer)


store.dispatch(increment)
store.dispatch(decrement)